﻿using Vowei.Data.Importer;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.Globalization;
using System.Linq;

namespace vowei.test
{
    
    
    /// <summary>
    ///这是 MapperDispatcherTest 的测试类，旨在
    ///包含所有 MapperDispatcherTest 单元测试
    ///</summary>
    [TestClass()]
    public class MapperDispatcherTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }
        
        /// <summary>
        ///Map 的测试
        ///</summary>
        [TestMethod()]
        public void MapTest()
        {
            var filename = Path.Combine(
                TestContext.TestDeploymentDir, @"MapperDispatcherTest_MapTest.xlsx");
            using (var stream = File.Open(filename, FileMode.Open, FileAccess.Read))
            {
                var actual = MapperDispatcher.Map(stream, true, new CultureInfo("en-us"));
                Assert.IsNotNull(actual.Project);
                Assert.AreEqual(7, actual.Requirements.Length);
                Assert.AreEqual(1, actual.Project.Children.Count());
                Assert.AreEqual("测试里程碑", actual.Project.Children.ElementAt(0).Title);
                Assert.AreEqual(0, actual.Project.Children.ElementAt(0).Children.Count());
                Assert.AreEqual(0, actual.Requirements[0].Children.Count());
                Assert.AreEqual(6, actual.Requirements[1].Children.Count());
                Assert.AreEqual(1, actual.Requirements[2].Children.Count());
                Assert.AreEqual(0, actual.Requirements[3].Children.Count());
                Assert.AreEqual(2, actual.Requirements[4].Children.Count());
                Assert.AreEqual(2, actual.Requirements[5].Children.Count());
                Assert.AreEqual(4, actual.Requirements[6].Children.Count());

                for ( int i = 0; i < actual.Requirements.Length - 1; ++i )
                    Assert.AreEqual(actual.Project, actual.Requirements[i].Milestone);

                Assert.AreEqual(actual.Project.Children.ElementAt(0), actual.Requirements[6].Milestone);
            }
        }
    }
}
